package com.timk.goserver.client.services;

import java.util.List;
import java.util.Set;

import com.google.gwt.user.client.rpc.RemoteService;
import com.timk.goserver.client.model.ClientGameInfo;

/**
 * Service for accessing games.
 * @author TKington
 *
 */
public interface GameService extends RemoteService {
	/** Success */
	int STATUS_SUCCESS = 0;
	/** Not your turn */
	int STATUS_WRONG_USER = 1;
	/** Playing an invalid move number */
	int STATUS_WRONG_MOVE_NUMBER = 2;
	/** No such game */
	int STATUS_NO_SUCH_GAME = 3;
	/** There was an automatic reply */
	int STATUS_AUTO_REPLY = 4;
	/** Illegal move */
	int STATUS_ILLEGAL_MOVE = 5;
	/** Illegal transition */
	int STATUS_ILLEGAL_STATE_TRANSITION = 6;
	/** Can't delete - too many moves played */
	int STATUS_CANT_DELETE = 7;
	
	/** Games where the player needs to move */
	int GAME_FILTER_NEXT_TO_MOVE = 0;
	/** Running games */
	int GAME_FILTER_RUNNING = 1;
	/** Finished games */
	int GAME_FILTER_FINISHED = 2;
	
	/** Running game */
	int GAME_STATE_RUNNING = 0;
	/** Completed game */
	int GAME_STATE_FINISHED = 1;
	
	/**
	 * Gets the list of games for a user
	 * @param username the user
	 * @param filter the filter value
	 * @param firstResult the first game to return
	 * @param maxResults the number of games to return
	 * @return List&lt;ClientGameInfo&gt;
	 * @throws NoSessionException if the session has expired
	 */
	List getGames(String username, int filter, int firstResult, int maxResults) throws NoSessionException;
	
	/**
	 * Gets a game by id
	 * @param gameid the id
	 * @return the ClientGameInfo
	 * @throws NoSessionException if the session has expired
	 */
	ClientGameInfo getGame(int gameid) throws NoSessionException;
	
	/**
	 * Plays moves in a game
	 * @param gameid the game id
	 * @param firstMoveNum the move number of the first move
	 * @param moves List&lt;Point&gt; of moves
	 * @param comment the comment
	 * @return integer error code
	 * @throws NoSessionException if the session has expired
	 * 
	 * @gwt.typeArgs moves <com.timk.goserver.client.compatibility.Point>
	 */
	int playMoves(int gameid, int firstMoveNum, List moves, String comment)
			throws NoSessionException;
	
	/**
	 * Submits the list of dead stones for scoring
	 * @param gameid the game id
	 * @param deadStones Set&lt;Point&gt; of dead stones
	 * @param comment the comment
	 * @return integer error code
	 * @throws NoSessionException if the session has expired
	 * 
	 * @gwt.typeArgs deadStones <com.timk.goserver.client.compatibility.Point>
	 */
	int submitDeadStones(int gameid, Set deadStones, String comment)
			throws NoSessionException;
	
	/**
	 * Resumes a game to dispute the status of groups
	 * @param gameid the game id
	 * @return integer error code
	 * @throws NoSessionException if the session has expired
	 */
	int resumeGame(int gameid) throws NoSessionException;
	
	/**
	 * Deletes a game
	 * @param gameid the game id
	 * @return integer error code
	 * @throws NoSessionException if the session has expired
	 */
	int deleteGame(int gameid) throws NoSessionException;
	
	/**
	 * Resigns a game
	 * @param gameid the game id
	 * @param comment the comment
	 * @return integer error code
	 * @throws NoSessionException if the session has expired
	 */
	int resignGame(int gameid, String comment) throws NoSessionException;
	
	/**
	 * Set private notes for the game
	 * @param gameid the game id
	 * @param notes
	 * @return integer error code
	 * @throws NoSessionException if the session has expired
	 */
	int setNotes(int gameid, String notes) throws NoSessionException;
}
